import { defHttp } from '@/utils/http/axios';
import { AxiosResponse } from 'axios';
import {
  LoginParams,
  LoginResultModel,
  GetUserInfoModel,
  GetSysUserInfoModel,
} from './model/userModel';

import { ErrorMessageMode } from '/#/axios';

enum Api {
  Login = '/auth/operation/login',
  LoginCode = '/code',
  Logout = '/logout',
  GetUserInfo = '/system/operator/setting/info',
  GetSysUserInfo = '/system/user/infoData',
  GetPermCode = '/getPermCode',
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * @description 获取登录code 图片
 * @date 11/07/2022
 */
export function loginCodeApi() {
  return defHttp.get<AxiosResponse<Blob>>(
    {
      url: Api.LoginCode,
      responseType: 'blob',
    },
    {
      isReturnNativeResponse: true,
    },
  );
}

/**
 * @description: getUserInfo
 */
/** 获取系统信息 */
export function getUserInfo() {
  return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo }, { errorMessageMode: 'none' });
}

/** 获取用户信息 */
export function getSysUserInfo() {
  return defHttp.get<GetSysUserInfoModel>(
    { url: Api.GetSysUserInfo },
    { errorMessageMode: 'none' },
  );
}

export function getPermCode() {
  return defHttp.get<string[]>({ url: Api.GetPermCode });
}

export function doLogout() {
  return defHttp.get({ url: Api.Logout });
}
